package com.hexseek.libretvcloud.service;


import com.hexseek.libretvcloud.mapper.HistoryMapper;
import com.hexseek.libretvcloud.model.History;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

/**
 * @author zhougb9
 * @version 1.0.0
 * @description TODO
 * @date 2025/5/14 17:57
 * @title HistoryService
 */
@Service
public class HistoryService {
    private final HistoryMapper mapper;

    public HistoryService(HistoryMapper mapper) {
        this.mapper = mapper;
    }

    // 保存搜索记录
    public void saveSearchHistory(String keyword, String userId) {
        History history = new History();
        history.setKeyword(keyword);
        history.setUserId(userId);
        history.setSearchTime(LocalDateTime.now());
        mapper.insert(history);
    }

    // 获取用户最近搜索记录
    public List<History> getRecentSearches(String userId) {
        return mapper.selectRecentSearch(userId);
    }

    // 清除用户搜索记录
    public void clearSearchHistory(String userId) {
        mapper.deleteByUserId(userId);
    }

    // 生成临时用户ID（如果没有登录用户）
    public String generateTempUserId() {
        return UUID.randomUUID().toString();
    }
}